/**
 Created by:
 muhtearjan mehmood مۇختەرجان مەخمۇت (Email: yeganaaa@163.com)
 At 2/10/20 11:39 PM
 */
import {AutomaticStreamStore, IStore} from "./AutomaticStreamStore";
import {EntityBase} from "entity_base";

export class SimpleStreamNotifier<T extends EntityBase<T>, STORE extends IStore<T>> implements IStore<STORE> {
    constructor(private entityConstructor: () => T) {
    }
    private mutationObject: any = {}
    data: T[] = []
    commit(action: string, payload: any): void {
        const fun = this.mutationObject[action]
        fun(this, payload)
        this.notifier()
    }
    public notifier = () => {}
    public streamer = new AutomaticStreamStore<T, SimpleStreamNotifier<T, STORE>>(
        "Data",
        () => this,
        storeState => storeState.data,
        (storeState, data1) => storeState.data = data1,
        () => this.entityConstructor()
    ).build(this.mutationObject)
}
